package edu.tec.mty.extras.fuzzy;

//Creates an Output Gaussian Membership Function 
public class OutputGaussMF {
	public String variable = "x";
	public String name = "OutputGauss"; // Name of the Input MF for the rules call
	public double sigma = 0.1; //Sigma 
	public double mean = 0.5; //Mean, also as sigma square are part of the Gaussian Function
	public double maxRange, minRange;  //Optional max and min Range Values for rounding purposes
	public double output;		//Output of the MF

public OutputGaussMF(String newname, String var,  double s, double m, double minR, double maxR){
	//GaussFunction throws exception in s <=0
	variable = var;
	name = newname;
	sigma = s;
	mean = m;
	minRange = minR;
	maxRange = maxR;
}

//Recalculates the resulting function of Fuzzy Rule
public double evaluation(double mFValue){
	
	if(mFValue < minRange){
		mFValue = minRange;
	}
	if (mFValue > maxRange){
		mFValue = maxRange;
	}
	
	try {
	GaussFunction GF = new GaussFunction(sigma, mean);
	output = mFValue * GF.evaluate(mean);
	} catch (Exception err) {
		output = 0;
	}
		
	return output;
}

//Publicate shows the current input
public String publicate(){
	return variable + " is " + name;
}

}